
<style> 
.colourRed{color: red;} 
</style> 
<script type="text/javascript">
var dialog_a;
//父页面参数 新增修改标示
var flag_one = addOrEditMusicInfoDialog.getData('flag_one');
var defaultImg = global_param.context_name+"/systemfiles/turningimags/defaultTurningImg.png";
var upload = 'http://'+window.location.hostname+':6'+window.location.port;
$(function(){
	//初始化化歌曲类型
	//typeSelect();
	//修改赋值
	if(flag_one == 'edit'){
		var music_id = addOrEditMusicInfoDialog.getData('music_id');
		evaluateMusic(music_id);
		$('#flag_one').val(music_id);
	}
	
});

//选择演唱人
var singPersonnelDialog;

$("#getSingPersonnel").click(function(){
		singPersonnelDialog = BootstrapDialog.show({												
		message: $('<div id="SingPersonnel" style="overflow:auto; height:610px;"></div>').load('static/html/musicManage/getSingPersonnel.html'),
		title: '员工列表',
		titleClass: 'text-center',
		closable: false,
		size:BootstrapDialog.SIZE_MIDDLE,
		buttons: [
			{
		        label: '保存',
		        cssClass:'btn btn-primary col-sm-1 col-sm-offset-4 col-xs-4 col-xs-offset-3',
		        action: function(dialog) {
		        	 evaluateSongPM();
		        	 dialog.close();
		        	 $("#SingPersonnel").html("");
		        }
		    },
			{
		    label: '取消',
		    cssClass:'btn btn-default col-sm-1 col-sm-offset-4 col-xs-4 col-xs-offset-3',
		    action: function(dialog) {
		    	$("#SingPersonnel").html("");
		    	$('#getSongPM').val("");
	    		$('#sing_personnel_id').val("");
		        dialog.close();
		    }
		}]
	});	 
}); 

//演唱人清空
$("#clearSingPersonnel").click(function(){
	$('#sing_personnel1').val('');
	$('#sing_personnel_id').val('');
});

//歌曲信息并赋值(修改用)
function evaluateMusic(music_id){
	$.ajax({
    	async: false,
    	url : global_param.context_name + '/song/LookAndEdit', 
		type : 'post', 
		data : {"music_id" : music_id},
		success: function(data){	
			$('#music_name1').val(data.music_name2);
			//$('#music_type1').val(data.music_type1);
			$('#sing_personnel1').val(data.sing_personnel2);
			$('#music_url').val(data.music_url2);
			$('#mv_url').val(data.mv_url2);
			$('#music_code2').val(data.music_code2);
			$('#pic_path').attr('src',global_param.context_name+data.pic_path2);
			var n1 = '';
			if(data.music_path2 != null ){
				n1 = data.music_name2+'.'+data.music_path2.split('.')[1];
			}else{
				n1 = data.music_name2+'.'+data.music_reduce_path2.split('.')[1];
			}
			$('#music_pathName_copy').val(n1);
			if(undefined != data.lyric_path2 && data.lyric_path2 != ''){
				var n2 = data.music_name2+'.'+data.lyric_path2.split('.')[1];
				$('#lyric_pathName_copy').val(n2); 
			}
			$('#sing_personnel_id').val(data.sing_personnel_id2);
			$("#sys_img_path").val(data.pic_path2);
		}  
  	});
}

/* function typeSelect (){
	$.ajax({
    	async: false,
    	url : global_param.context_name + '/song/getMusicType', 
		type : 'post',  				    
		success: function(data){			
			var output = [];
			output.push("<option value=''>请选择</option>");
			$.each(data, function(key, value)
			{
				output.push('<option value="'+ value.KEY +'">'+ value.value +'</option>');
			});
			
			$('#music_type1').html(output.join(''));  
		}  
  	});
} */

function musicSave(dialog){	

	if(check()){
		$("body").startLoading();
		var form = document.getElementById('uploadMusic'), 
		formData = new FormData(form); 
		$.ajax({ 
			url:global_param.context_name+"/song/musicSave", 
			type:"post", 
			data:formData, 
			processData:false, 
			contentType:false, 
			success:function(res){ 
				$("body").stopLoading();
				if(res == 'success'){
					globalUtil.showSuccessMessage('操作成功');
				}else{
					globalUtil.showErrorMessage('操作失败');
				}
				dialog.close();
				refreshMusic();
			}
		});
	}
}

function musicUpdSave(dialog){
	if(check()){
		$("body").startLoading();
		var form = document.getElementById('uploadMusic'), 
		formData = new FormData(form); 
		$.ajax({ 
			url:global_param.context_name+"/song/musicSave", 
			type:"post", 
			data:formData, 
			processData:false, 
			contentType:false, 
			success:function(res){ 
				$("body").stopLoading();
				if(res == 'success'){
					globalUtil.showSuccessMessage('操作成功');
				}else{
					globalUtil.showErrorMessage('操作失败');
				}
				dialog.close();
				refreshMusic();
			}
		});
	}
}

function check(){
	var check_flag = true;
	if($('#music_name1').val()==''){
		globalUtil.showSuccessMessage("请填写歌曲名称");
		check_flag = false;
		return false;
	}
	if($('#sing_personnel1').val()==''){
		globalUtil.showSuccessMessage("请选择演唱人");
		check_flag = false;
		return false;
	}
	if($('#music_pathName_copy').val()==''){
		globalUtil.showSuccessMessage("请选择歌曲文件");
		check_flag = false;
		return false;
	}
	if($('#sys_img_path').val()==''){
		globalUtil.showSuccessMessage("歌曲背景不能为空");
		check_flag = false;
		return false;
	}
	
	if($('#music_name1').val().length > 20){
		globalUtil.showSuccessMessage("歌曲名称不能超过20字");
		check_flag = false;
		return false;
	}
	
	var t = $('#music_pathName_copy').val().substring($('#music_pathName_copy').val().length-3);
	if(t.toUpperCase() != 'MP3' && t.toUpperCase() != 'WAV'){
		globalUtil.showSuccessMessage("歌曲文件请选择mp3或wav文件");
		check_flag = false;
		return false;
	}
	
	if($('#lyric_pathName_copy').val()!=''){
		var a = $('#lyric_pathName_copy').val().substring($('#lyric_pathName_copy').val().length-3);
		if(a.toUpperCase() != 'LRC' ){
			globalUtil.showSuccessMessage("歌词文件请选择lrc文件");
			check_flag = false;
			return false;
		}
	}
			
	return check_flag;
}

function clearMusicPath(){
	$('#music_pathName').val('');
	$('#music_pathName_copy').val('');
}

function clearLyricPath(){
	$('#lyric_pathName_copy').val('');
	$('#lyric_pathName').val('');
}

//file文件名
function getFileName(o){
    var pos=o.lastIndexOf("\\");
    return o.substring(pos+1);  
}


//歌曲背景
function MusicPic(){
	BootstrapDialog.show({												
		message: $('<div id="MusicPic" style="min-height: 450px;" ></div>').load('static/html/musicManage/MusicPic.html'),
		title: '上传歌曲背景照片',
		titleClass: 'text-center',
		closable: false,
		size:BootstrapDialog.SIZE_MIDDLE,
		buttons: [
			{
		        label: '保存',
		        cssClass:'btn btn-primary col-sm-1 col-sm-offset-4 col-xs-4 col-xs-offset-3',
		        action: function(dialog) {
		        	dialog_a = dialog;
		        	addImgs();
	        		//dialog.close();
		        }
		    },
			{
		    label: '取消',
		    cssClass:'btn btn-default col-sm-1 col-sm-offset-4 col-xs-4 col-xs-offset-3',
		    action: function(dialog) {
		    	$("#MusicPic").html("");
		        dialog.close();
		    }
		}]
	});	
}

//删除图片
function deleteImg1(){
	//删除当前页面图片
	if($('#pic_path').attr('src')==defaultImg){
		return;
	}
	if(flag_one=="edit"){
		//修改时删除
		$('#pic_path').attr('src','static/img/defaultImg/defaultSquareImg.png');
	    $('#sys_img_path').val('');
	    toastr.success("操作成功");
	}else if(flag_one=="add"){
		//新增时删除
		  $.ajax({
		        type: "POST",
		        url: global_param.context_name + "/personnelManage/deleteImg.do",
		        data:{
		            "oldFileName": $('#sys_img_path').val(),
		            "defaultImg":defaultImg
		        },
		        async: false,
		        success: function(json) {
		        	if(json=="success"){
		        		toastr.success("操作成功");
		        		$('#pic_path').attr('src','static/img/defaultImg/defaultSquareImg.png')
		        	    $('#sys_img_path').val('');
		        	}
		        	
		        }
		    }); 
		}
}

function checkFileExt(filename,type){
	//取出上传文件的扩展名
	var index = filename.lastIndexOf(".");
	var ext = filename.substr(index+1);
	if(type == '1'){
		var file = $("#music_pathName").val();
		var fileName = getFileName(file);  
		$('#music_pathName_copy').val(fileName);
	}else if(type == '2'){
		var file = $("#lyric_pathName").val();
		var fileName = getFileName(file);  
		$('#lyric_pathName_copy').val(fileName);
	}
}

</script>

	<div class="row">
		<div class="box">
			<div class="box-body">
			<form id="uploadMusic" enctype="multipart/form-data" method="post"> 
				<div class="col-lg-5 col-md-6 col-sm-6 col-xs-12">
	              	<div class="form-group">
		              	<label for="music_name">歌曲名称<span class="colourRed">*</span></label>
		                <input type="text" class="form-control inblock form-width"  id="music_name1" name="music_name" placeholder="请输入少于20个汉字">
	              	</div>
		         </div>
				
				<!--  <div class="col-lg-5 col-md-6 col-sm-6 col-xs-12">
		            	<div class="form-group">
		             		<label for="music_type">歌曲类型<span class="colourRed">*</span></label>
		             		<select class="form-control inblock form-width" id="music_type1" name="music_type" >
				            	
			                </select> 
		               </div>
		         </div> -->
		         
		         <div class="col-lg-8 col-md-6 col-sm-6 col-xs-12">
	              	<div class="form-group">
		              	<label for="sing_personnel">演唱人<span class="colourRed">*</span>&nbsp;&nbsp;&nbsp;</label>
		                <input type="text" readonly="readonly" id="sing_personnel1" class="form-control inblock form-width" name="sing_personnel">
		                <div class="inblock">
			             	<input type="button" id="getSingPersonnel" class="btn btn-primary" value="选择"></input> 
			                <input type="button" id="clearSingPersonnel" class="btn btn-default" value="清空"></input>  
		                </div>
	              	</div>
	              	
		         </div>
		         
		         <div class="col-lg-12 col-md-6 col-sm-6 col-xs-12">
	              	<div class="form-group">
	              		<label for="music_path">歌曲文件<span class="colourRed">*</span></label>
	              		<input id="music_pathName_copy" type="text" class="form-control inblock form-width " readonly="readonly"/>
		              	<input id="music_pathName" type="file" onchange="checkFileExt(this.value,1)" accept=".mp3,.wav" class="form-control inblock form-width-copy " name="file" style="border: none"/>
		              	<div class="inblock">		              	
		              	   <a onclick="clearMusicPath()" style="cursor: pointer;">删除文件</a>
		              	</div>
	              	</div>
		         </div> 
		         
		         <!--<div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">
	              	<div class="form-group">
		              	<label for="music_path">选择</label>
		              	<input id="music_path" type="file" class="form-control " name="file" onchange="keyFile();"/>
	              	</div>
		         </div>    
		         
		         <div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">
	              	<div class="form-group">
		              	<label for="music_path">删除</label>		              	
		              	<a onclick="clearMusicPath()" class="form-control">删除文件</a>
	              	</div>
		         </div> 
		          --> 
		         <!-- <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12"> -->
		         <div class="col-lg-12 col-md-6 col-sm-6 col-xs-12">
	              	<div class="form-group">
	              		<label for="lyric_path">歌词文件<span>&nbsp;</span></label>
	              		<input id="lyric_pathName_copy" type="text" class="form-control inblock form-width " readonly="readonly" name = "lyric_pathName_copy"/>
	              	   	<input id="lyric_pathName" type="file" onchange="checkFileExt(this.value,2)" accept=".LRC" class="form-control inblock form-width-copy " name="file" style="border: none"/>
	              	    <div class="inblock">
		              	   <a onclick="clearLyricPath()" style="cursor: pointer;">删除文件</a>
		                </div>
	              	</div>
		         </div> 
		         
		         <!-- <div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">
	              	<div class="form-group">
		              	<label for="lyric_path">选择</label>
		              	<input id="lyric_path" type="file" class="form-control" name="file" onchange="lyricPathFile()"/>
		              	
	              	</div>
		         </div>    
		         
		         <div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">
	              	<div class="form-group">
		              	<label for="lyric_path">删除</label>		              	
		              	<a onclick="clearLyricPath()" class="form-control">删除文件</a>
	              	</div>
		         </div> 
		         --> 		       		      
		         <!-- <div class="col-lg-10 col-md-6 col-sm-6 col-xs-12"> -->
		         <div class="col-lg-12 col-md-6 col-sm-6 col-xs-12">
	              	<div class="form-group">
		              	<label for="music_url">歌曲地址</label>
		                <input type="text" class="form-control inblock music-width" id="music_url" style="margin-left:2px" name="music_url">
	              	</div>
		         </div>
		         
		         <div class="col-lg-10 col-md-6 col-sm-6 col-xs-12">
	              	<div class="form-group">
		              	<label for="mv_url">MV地址</label>
		                <input type="text" class="form-control inblock music-width" id="mv_url" style="margin-left:10px" name="mv_url">
	              	</div>
		         </div>
		         
		         <!-- <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
	              	<div class="form-group">
		              	<label for="pic_path" style="valign:top">歌曲背景</label>
		                <img alt="背景" style="width:300px;height:200px" id="pic_path" src="/static/img/111.png">
		                <a onclick="MusicPic()">上传</a> <a onclick="deleteImg1()">删除</a>
	              	</div>
		         </div> -->
		         <div class="col-lg-12 col-md-6 col-sm-6 col-xs-12">
	              	<div class="form-group " id="myPic">
		              	<label for="pic_path" style="display:table-cell; vertical-align: middle;">歌曲背景<span class="colourRed">*</span></label>
		              	<!-- <div style="border-radius:100%"></div> -->
		              	<img alt="背景" style="height:260px;margin-left:65px;margin-top:-16px" id="pic_path" src="static/img/defaultImg/defaultSquareImg.png">
		              	<div class="inblock" style="margin-top:200px;display:table-cell; vertical-align: middle;">
		                 <input type="button" onclick="MusicPic()" value="上传" class="btn btn-primary"></input> 
		                 <input type="button" onclick="deleteImg1()" value="删除" class="btn btn-default"></input>
		                </div>
	              	</div>
		         </div>
		         <input type="hidden" id="music_source" name="music_source" value="0">
		         <input type="hidden" id="sys_img_path" name="sys_img_path">
		         <input type="hidden" id="pic_path_mini" name="pic_path_mini">
		         <input type="hidden" id="music_code2" name="music_code2">
		         <input type="hidden" id="flag_one" name="music_id">
		         <input type="hidden" id="sing_personnel_id" name="sing_personnel_id">
		    </form> 
			</div>
		</div>
	</div>
